<template>
	<view class="container">
		<!-- 搜索框 -->
		<view class="search-section">
			<view class="search-input u-f-ajc">
				<u-search bg-color="#f4f4f4" shape="square" placeholder="请输入您喜欢的商品" @search="search" :show-action="false"
				 :clearabled="true" v-model="keyword"></u-search>
			</view>
		</view>
		<view class="index-elements" v-for="component in components_list" :key="component.id">
			<!-- 轮播图 -->
			<view class="swiper-section" v-if="component.type == 'banner'">
				<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" indicator-active-color="#fff">
					<swiper-item v-for="item in component.data" :key="item.id" @click="$jump(item.linkUrl)">
						<view class="swiper-item">
							<image :src="item.imgUrl" mode=""></image>
						</view>
					</swiper-item>
				</swiper>
			</view>

			<uni-carousel v-if="component.type == 'nav'" :carouselList="Object.values(component.data)" height="90" :type="component.style.type"
			 :num="component.style.num" @onCarousel="onCarousel"></uni-carousel>

			<!-- 头条 -->
			<view class="notice-section" v-if="component.type == 'title'">
				<view class="notice u-f-ac">
					<image src="../../static/img/index_notice.png" mode=""></image>
					<view class="line"></view>
					<view class="content" @click="$jump('/pages/service/notice')">{{ component.data }}</view>
				</view>
			</view>

			<!-- 海报图片-->
			<view class="pic-group" v-if="component.type == 'adimg'">
				<view :class="[`pic-style pic-style-${component.style.type}`]">
					<image v-if="component.style.type == 1 || component.style.type == 5 || component.style.type == 7" v-for="(item, id, index) in component.data"
					 :key="index" class="img-pic" :src="item.imgUrl" @click="$jump(item.linkUrl)" mode="widthFix"></image>
					<image v-else v-for="(item, id, index) in component.data" :key="item.id" class="img-pic" :src="item.imgUrl" @click="$jump(item.linkUrl)"></image>
				</view>
			</view>
			<!-- 商品列表 -->
			<view class="goods-section" v-if="component.type == 'goods_list'">
				<view class="goods-header">{{ component.style.title }}</view>
				<view class="goods-list u-f-jsb u-f-fw">
					<view class="goods-item" v-for="(item, index) in component.data" :key="index" @click="$jump(item.url)">
						<image :src="item.logo" mode=""></image>
						<view class="title u-line-clamp">{{ item.title }}</view>
						<view class="price u-f-ac">
							<view style="font-size: 28upx;">￥</view>
							{{ item.price_market }}
							<text>￥{{ item.price_cost }}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="height: 150upx;background-color: #f3f3f3;"></view>
		<view class="popup1" v-if="show">
			<view class="mask"></view>
			<view class="shade">
				<view class="list">
					<view style="display: flex;flex-direction: column;height: 782upx;margin-bottom: 44upx;position: relative;padding:0 33upx;">
						<image style="width: 100%;height: 782upx;display: flex;justify-content: center;" src="../../static/img/index-bg.png"
						 mode=""></image>
						<view style="position: absolute;bottom: 30upx;left: 0px;width: 100%;">
							<view style="font-size: 32upx;font-weight: 400;color: #7B889B;line-height: 50upx;text-align: center;display: flex;justify-content: center;flex-direction: column;">
								<view>您当前收益已经达到{{num}}元</view>
								<view style="margin-bottom: 54upx;">请原点复投</view>
							</view>
							<view style="display: flex;justify-content: space-around;align-items: center;margin: 0 36upx;">
								<view style="position: relative;" @click="show=!show">
									<image style="width: 262upx;height: 86upx;" src="../../static/img/index-color.png" mode=""></image>
									<view style="position: absolute;top:20upx;left: 84upx;color: #fff;">去复投</view>
								</view>
								<view style="position: relative;" @click="show=!show">
									<image style="width: 262upx;height: 86upx;" src="../../static/img/index-color1.png" mode=""></image>
									<view style="position: absolute;top:20upx;left: 56upx;color: #fff;">我再考虑一下</view>
								</view>
							</view>
						</view>
					</view>
					<view style="margin-bottom: 100upx;display: flex;justify-content: center;" @click="show=!show">
						<image style="width: 104upx;height: 104upx;" src="../../static/img/index-close.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<!-- #ifndef APP-PLUS -->
		<tabbar :current-page="0"></tabbar>
		<!-- #endif -->
	</view>
</template>

<script>
	import service from '@/store/service.js';
	import uicons from '@/components/uni-icons/uni-icons.vue';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';

	export default {
		components: {
			uicons,
			uniLoadMore
		},
		data() {
			return {
				show: false,
				keyword: '',
				components_list: [],
				goodList: [],
				num: ''
			};
		},
		onLoad: function(e) {
			this.showPage();
			this.getAgent()
		},
		methods: {
			getAgent() {
				var self = this;
				self.$http.get(service.api.user.getAgent, {}).then(function(res) {
					var list = res.data;
					self.num = list.consumption
					if (list.repurchase == 1) {
						self.show = true
					}
				});
			},
			search(value) {
				console.log(value);
				uni.navigateTo({
					url: '../shoppingCart/searchList?keyword=' + value
				});
			},
			showPage: function() {
				let self = this;
				this.$http.get(service.api.main.getpage).then(function(res) {
					if (res.code == 1) {
						self.components_list = res.data;
					}
				});
			},

			onCarousel: function(item) {
				var url = item.linkUrl;
				if (url == '') {
					uni.showToast({
						icon: 'none',
						title: '该功能暂未开放'
					});
				} else {
					if (url == '/pages/business/business') {
						// 获取入驻申请信息
						this.$http.post(service.api.index.getApplyInfo).then(res => {
							console.log(res, 'info-res');
							if (res.code === 1) {
								if (res.data.status === 1) {
									uni.navigateTo({
										url: '../business/store?merch_id=' + res.data.merch_id
									})
									return
								} else {
									uni.navigateTo({
										url: url
									});
								}
							}
						})
					} else {
						uni.navigateTo({
							url: url
						});
					}
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	.container {
		background-color: $uni-bg-color;

		.search-section {
			width: 100vw;
			padding: 30rpx;

			.search-input {
				width: 690rpx;
				height: 66rpx;
				background-color: #f1f1f1;
				border-radius: 33rpx;

				text {
					margin-left: 10rpx;
					color: $uni-text-color-grey;
				}
			}
		}

		.index-elements {
			.swiper-section {
				width: 100vw;
				height: 100%;
				padding: 20rpx;

				.swiper {
					height: 100%;
				}

				.swiper-item {
					width: 710rpx;
					height: 100%;

					image {
						width: 100%;
						height: 100%;
						border-radius: 10upx;
					}
				}
			}

			.menu-section {
				display: flex;
				flex-wrap: wrap;
				align-items: center;

				//display: flex;
				.menu-item {
					width: 25%;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					margin-top: 20upx;
					margin-bottom: 20upx;
					font-size: 20upx;

					image {
						width: 80rpx;
						height: 80rpx;
						padding-bottom: 20upx;
					}
				}
			}
		}

		.notice-section {
			padding: 20rpx;

			.notice {
				width: 710rpx;
				height: 72rpx;
				border-radius: 33rpx;
				display: flex;
				background-color: #f4f4f4;
				line-height: 72rpx;

				image {
					width: 121rpx;
					height: 32rpx;
					margin: 20upx 0;
					padding-left: 20rpx;
				}

				.line {
					width: 2rpx;
					height: 32rpx;
					background-color: #c3c3c3;
					margin: 20rpx 15rpx;
				}

				.content {
					color: $uni-text-color;
					font-weight: bold;
				}
			}
		}

		.group-section {
			padding: 20rpx;
			border-bottom: 20rpx solid #f3f3f3;
			box-sizing: border-box;
			width: 100%;

			.group-header {
				.title {
					font-size: 32rpx;
					font-weight: bold;
					color: #000;
				}

				.sub-title {
					font-size: 22rpx;
					color: #999;
					margin-left: 20rpx;
				}

				image {
					width: 94rpx;
					height: 26rpx;
				}
			}

			.group-content {
				display: flex;
				overflow: hidden;

				.group-item {
					// width: 225rpx;
					width: 32%;
					margin: 15rpx;

					image {
						width: 224rpx;
						height: 224rpx;
						margin: 20rpx 0 10rpx;
					}

					.content {
						box-sizing: border-box;
						width: 224rpx;
						height: 47rpx;
						display: flex;
						justify-content: space-around;
						background: linear-gradient(90deg, #ffcc99, #e4842e);
						border-radius: 0px 0px 18upx 18upx;

						.label {
							padding: 0 10upx;
							// width: 128rpx;
							height: 42rpx;
							font-size: 20rpx;
							line-height: 42rpx;
							text-align: center;
							// display: flex;
							// justify-content: center;
							// align-items: center;
							transform: scale(0.9);
							background: #f69739;
							border-radius: 18upx;
						}

						.price,
						.label {
							color: #ffffff;
						}

						.price {
							font-size: 24upx;
							font-weight: bold;
						}
					}

					.name {
						width: 224rpx;
						margin-top: 10rpx;
						// text-align: center;
					}
				}

				& :nth-child(1),
				& :nth-child(3) {
					margin-left: 0;
					margin-right: 0;
				}
			}
		}

		.goods-section {
			background-color: #f3f3f3;
			padding: 0 20rpx 0;

			.goods-header {
				color: #262626;
				font-size: 34rpx;
				font-weight: bold;
				margin-bottom: 20rpx;
			}

			.goods-list {
				// margin-bottom: 50rpx;
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;

				.goods-item {
					border-radius: 20upx;
					width: 345rpx;
					background-color: #ffffff;
					margin-bottom: 20rpx;

					image {
						width: 100%;
						height: 330rpx;
						margin-bottom: 20rpx;
						border-radius: 20upx 20upx 0 0;
					}

					.title {
						padding: 10rpx 30rpx 0;
						font-size: 26rpx;
						color: $uni-text-color;
						font-weight: bold;
						line-height: 1.4;
					}

					.price {
						padding: 14rpx 24rpx;
						font-size: 36rpx;
						font-weight: bold;
						color: #f81149;

						text {
							font-weight: 100;
							font-size: 20rpx;
							color: #999;
							text-decoration: line-through;
							margin-left: 15rpx;
						}
					}
				}
			}
		}
	}

	.pic-group {
		padding: 20upx;
	}

	.img-pic {
		display: none;
	}

	.pic-style {
		display: flex;
		justify-content: space-around;
		position: relative;
		z-index: 1;
		margin: 0 auto;
		width: 100%;

		image {
			width: 100%;
			z-index: -1;
			zoom: 1;
		}
	}

	.pic-style-1 {
		flex-direction: column;
		align-items: center;

		image {
			display: block;
			width: 100%;
		}
	}

	.pic-style-2 {
		image {
			&:nth-child(1) {
				display: block;
				width: 40%;
				height: 365upx;
			}

			&:nth-child(2) {
				display: block;
				width: 60%;
				height: 365upx;
			}
		}
	}

	.pic-style-3 {
		height: 365upx;

		image {
			&:nth-child(1) {
				display: block;
				width: 40%;
				height: 365upx;
				position: absolute;
				left: 0;
			}

			&:nth-child(2) {
				display: block;
				width: 60%;
				height: 180upx;
				position: absolute;
				right: 0;
			}

			&:nth-child(3) {
				display: block;
				width: 60%;
				height: 180upx;
				position: absolute;
				// right: 222upx;
				right: 0;
				bottom: 0;
			}

			// &:nth-child(4) {
			// 	display: block;
			// 	width: 216upx;
			// 	height: 180upx;
			// 	position: absolute;
			// 	right: 0;
			// 	bottom: 0;
			// }
		}
	}

	.pic-style-4 {
		height: 365upx;

		image {
			&:nth-child(1) {
				display: block;
				width: 40%;
				height: 365upx;
				position: absolute;
				left: 0;
			}

			&:nth-child(2) {
				display: block;
				width: 60%;
				height: 180upx;
				position: absolute;
				right: 0;
			}

			&:nth-child(3) {
				display: block;
				width: 216upx;
				height: 180upx;
				position: absolute;
				right: 222upx;
				bottom: 0;
			}

			&:nth-child(4) {
				display: block;
				width: 216upx;
				height: 180upx;
				position: absolute;
				right: 0;
				bottom: 0;
			}
		}
	}

	.pic-style-5 {
		display: flex;
		justify-content: space-around;

		image {
			flex: 1;
			margin: 0 5upx;

			&:first-child {
				margin: 0;
				display: block;
			}

			&:nth-child(2) {
				margin-right: 0;
				display: block;
			}

			&:nth-child(3) {
				display: block;
			}

			&:nth-child(4) {
				margin: 0;
				display: block;
			}
		}
	}

	.pic-style-6 {
		display: flex;
		flex-wrap: wrap;

		>image {
			&:nth-child(1) {
				display: block;
				width: 50%;
				height: 200upx;
				margin-top: 5upx;
			}

			&:nth-child(2) {
				display: block;
				width: 50%;
				height: 200upx;
				margin-top: 5upx;
			}

			&:nth-child(3) {
				display: block;
				width: 50%;
				height: 200upx;
				margin-top: 5upx;
			}

			&:nth-child(4) {
				display: block;
				width: 50%;
				height: 200upx;
				margin-top: 5upx;
			}
		}
	}

	.pic-style-7 {
		display: inline-flex;
		flex-flow: row wrap;
		align-content: flex-start;

		image {
			display: block;
			box-sizing: border-box;
			flex: 0 0 50%;
		}
	}

	.pic-style-8 {
		image {
			flex: 1;

			&:nth-child(1) {
				display: block;
				height: 250upx;
			}

			&:nth-child(2) {
				display: block;
				height: 250upx;
			}

			&:nth-child(3) {
				display: block;
				height: 250upx;
			}
		}
	}

	/deep/ .u-content {
		background-color: #f4f4f4 !important;
	}

	.good-list {
		margin: 20upx 20upx 0;

		.good-item {
			border-radius: 20upx;
			width: 220rpx;
			background-color: #ffffff;
			margin-bottom: 20rpx;

			image {
				width: 100%;
				height: 220rpx;
				margin-bottom: 20rpx;
			}

			.title {
				padding: 10rpx 10rpx 0;
				font-size: 26rpx;
				color: $uni-text-color;
				font-weight: bold;
				line-height: 1.4;
			}

			.price {
				padding: 14rpx;
				font-size: 28rpx;
				font-weight: bold;
				color: #f81149;

				text {
					font-weight: 100;
					font-size: 20rpx;
					color: #999;
					margin-left: 15rpx;
				}
			}
		}
	}

	.pic {
		width: 92%;
		height: 175upx;
		margin-left: 30upx;
		// margin-top: 20upx;
	}


	.popup1 {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 999;
	}

	.cancel {
		width: 687upx;
		height: 145upx;

		background: #F4F4F4;
		position: fixed;
		bottom: 0;

		view {
			height: 100upx;
			line-height: 100upx;
			background: #FFFFFF;
			border: 1px solid #E6E6E6;
			border-radius: 12upx;
			text-align: center;
		}
	}

	.mask {
		position: fixed;
		top: 0;
		width: 100%;
		height: 100%;
		z-index: 1;
		background-color: rgba(0, 0, 0, 0.4);
	}

	.shade {
		width: 100%;
		height: 782upx;
		// overflow: scroll;
		// min-height: 40vh;
		// background: #F4F4F4;
		position: fixed;
		bottom: 0;
		top: 160upx;
		z-index: 99;
		padding-bottom: 60px;
	}

	.list-scroll-content {
		height: 100%;
	}

	.list {
		padding: 30upx;

		.box {
			width: 690upx;
			height: 194upx;
			background: #FFFFFF;
			border: 1px solid #E6E6E6;
			border-radius: 12upx;
			margin-bottom: 30upx;

			.content {
				display: flex;
				justify-content: space-around;

				.box-left,
				.box-left1,
				.box-left2 {
					width: 212upx;
					height: 194upx;
					background: #F81149;
					box-shadow: 3upx 0px 8upx 1px #FCE1E8;
					border-radius: 12upx 0px 0px 12upx;
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: center;

					.icon {
						margin-top: 20upx;
						height: 49upx;
						font-size: 40upx;
						// font-weight: bold;
						color: #FFFFFE;
						line-height: 59upx;
						text-align: center;
					}

					.num {
						font-size: 80upx;
						font-weight: bold;
						color: #FFFFFE;
						line-height: 72upx;
					}

				}

				.box-left1 {
					background: #c1c1c1;
				}

				.box-left2 {
					background: #F86A8C;
				}


				.right {
					display: flex;
					justify-content: space-between;
					align-items: center;
				}

				.box-center {
					display: flex;
					align-items: center;
					justify-content: center;
					flex-direction: column;
					margin-right: 20upx;

					.text {
						font-weight: bold;
						color: #242424;
						font-size: 36upx;
						margin-bottom: 10upx;
					}

					.time {
						font-size: 24upx;
						color: #999999;
						transform: scale(0.9);
					}
				}

				.box-right {
					display: flex;
					align-items: center;
					justify-content: center;

					.text,
					.text1,
					.text2 {
						width: 140upx;
						height: 58upx;
						background: #FFFFFF;
						border: 2upx solid #F81149;
						border-radius: 29upx;
						text-align: center;
						margin-right: 22upx;
						font-size: 32upx;
						font-weight: 500;
						color: #F81149;
						text-align: center;
					}

					.text1 {
						border: 2upx solid #C1C1C1;
						color: #C1C1C1;
					}

					.text2 {
						border: 2upx solid #F86A8C;
						color: #F86A8C;
					}
				}
			}
		}
	}

	// 优惠券
	.discount-bg {
		background-image: url(../../static/img/bg.png);
		background-size: 100% 100%;
		width: 100upx;
		height: 36upx;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #FFFFFF;
		margin-right: 20upx;
	}

	.icons {
		font-size: 12px;
	}

	.container {
		position: fixed;
		top: 0;
		height: 100%;
		overflow: hidden;
	}
</style>
